package com.smartwork.common.mobile.wechat.service;


import com.alibaba.fastjson.JSONObject;
import com.smartwork.common.mobile.wechat.constant.StaticValue;
import com.smartwork.common.mobile.wechat.util.WeixinConfUtils;
import com.smartwork.common.mobile.wechat.util.WeixinUtil;
import org.springframework.stereotype.Service;


@Service("tokenService")
public class TokenService {

	public JSONObject getOAuthToken(String groupId, String code) throws Exception {
        String[] app = WeixinConfUtils.getAppIDAndAppSecretByGroupId(groupId);
		String tokenUrl = String.format(StaticValue.oAuthTokenUrl, app[0], app[1], code);
		JSONObject jsonObject = WeixinUtil.httpRequest(tokenUrl, "GET", null);
		return jsonObject;
	}

}
